<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="./css/mui.min.css">
    <link rel="stylesheet" href="./css/main.css">
    <title>查询结果</title>
</head>

<body>
    <div class="wrap">

    </div>
    <script src="./js/jquery-3.2.1.min.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/path.js"></script>
    <script src="./js/mui.min.js"></script>
    <script type="text/javascript">
        var custOrBuyerName = decodeURI(getQueryString('custOrBuyerName'));
        var state = decodeURI(getQueryString('state'));
        var date = decodeURI(getQueryString('date'));
        $(document).ready(function(){
            $.ajax({
                url: path + '/app/invoiceRecord/list',
                type:'post',
                dataType:'json',
                data:{
                    custOrBuyerName : custOrBuyerName,
                    state : state,
                    period : date
                },
                success:(data)=>{
                    var html='';
                    if(data.data.length>0){
                        for (var i = 0; i < data.data.length; i++) {
                            html+='<div class="resultSelect">';
                            html+='<div class="resulttop">';
                            html+='<span class="result_money">￥'+data.data[i].invoicetotalmoney+'</span>';
                            html+='<span class="result_time">提交时间:'+data.data[i].createtime+'</span>';
                            html+='</div>';
                            html+=' <p class="resultP">委方：'+data.data[i].conCustomername+'</p>';
                            html+=' <p class="resultP" style="border-bottom:1px dotted #c0c0c0;">购方：'+data.data[i].buyerName+'</p>';
                            html+='<div class="resulttop">';
                            html+='<input type="hidden" value="'+data.data[i].invoiceRecordId+'"/><span class="result_time " style="color:#333"><img src="./images/company_search.png" alt="" class="icon-search"/>查看详情</span>';
                            if(data.data[i].state==1){
                                html+='<span class="result_cancel cancel_invice" style="color:#333"><img src="./images/express_delete.png" alt="" class="icon-del"/>取消开票</span>';
                            }
                            // else if(data.data[i].state==2){
                            //     html+='<span class="result_cancel " style="color:#333">处理中</span>';
                            // }else if(data.data[i].state==3){
                            //     html+='<span class="result_cancel " style="color:#333">已完成</span>';
                            // }else if(data.data[i].state==4){
                            //     html+='<span class="result_cancel " style="color:#333">已取消</span>';
                            // }
                            html+='</div>';
                            html+='</div>';
                        }
                    }else{
                        html+='<img src="./images/result_oops.png" alt="" class="result_oops"/>';
                        html+='<p class="result_note">暂无记录！</p>';
                    }
                    $(".wrap").append(html);
                },
                error:(err)=>{
                    mui.alert(err.message)
                }
            })
        })
        // 跳转到详情
        $(document).on('touchstart','.result_time',function(){
            var invoiceRecordId = $(this).parent().find('input').val();
            var type = decodeURI(getQueryString('type'));
            var state = decodeURI(getQueryString('state'));
            window.location.href='./DetailInvoice.html?invoiceRecordId='+invoiceRecordId+'&type='+type+'&state='+state;
        })
        // 取消开票
        $(document).on('touchstart','.cancel_invice',function(){
            var invoiceRecordId = $(this).parent().find('input').val();
            $.ajax({
                url:path + '/app/invoiceRecord/cancel',
                dataType:'json',
                type:'post',
                data:{
                    invoiceRecordId : invoiceRecordId
                },
                success:(data)=>{
                     console.log(data);
                     if(data.success=1){
                         mui.alert(data.message,function(){
                             window.location.replace('./user.html');
                         });
                     }
                },
                error:(err)=>{
                    mui.alert(err.message)
                }
            })
        })
    </script>
</body>

</html>
